package org.mybatis.logic;

import org.mybatis.logic.mybatis.BusinnessLogicSqlDataBaseImpl;

public class BusinessLogic<T> {
	/**
	 * scope: application
	 */
	
	protected BusinnessLogicSqlDataBase<T> bSql;

	public static final short MYBATIS_SQLITE_ACCESS = 0;
	public static final short ANDROID_SQLITE_ACCESS = 1;
	
	public BusinessLogic(short accessType) throws Exception {		
		System.out.println("Costruttore");

		switch ( accessType ) {
		case MYBATIS_SQLITE_ACCESS:
			bSql = new BusinnessLogicSqlDataBaseImpl<T>() {};		
			break;
		case ANDROID_SQLITE_ACCESS:
			bSql = new BusinnessLogicSqlDataBaseImpl<T>() {};
			break;
		default:
			throw new Exception("Specificare il tipo di accesso al dato");
			
		}
		
	}	
	
	public void openSession(){
		bSql.openSession();
	}
	
	public void setMapper(Class<T> c){
		try {
			System.out.println("OOOO");
			bSql.setMapper(c);
			System.out.println("OO");
		} catch ( Exception e){
			e.printStackTrace();
		}
	}
	
	public T getMapper(Class<T> c){
		T mapper = null;
		try {
			System.out.println("OOOO");
			mapper = bSql.getMapper();
			System.out.println("OO");
		} catch ( Exception e){
			e.printStackTrace();
		}
		return mapper;
	}
	public void commitSession(){
		bSql.commit();
	}
	
	public void closeSession(){
		bSql.close();
	}
}
